home *** CD-ROM | disk | FTP | other *** search
- code segment
- assume cs:code
-
- ; FUNCTION called from Turbo Pascal, executes .COM
- ; or .EXE programs using the DOS function 4BH.
- ; Preserves the stack registers, returning the
- ; error code 0 if succesfull or the DOS error code
- ; if the execute fails.
-
- ; Pascal declaration:
- ; FUNCTION DOS4BH(VAR PROGRAM_NAME,PARAMETER_STRING):INTEGER
-
- arguments struc ; Template to arguments.
- save_bp dw ? ; Saved BP register.
- ret_adr dw ? ; Return address (near call).
- ;-----------------------------------------------------------------
- param_str dd ? ; DWORD pointer to param. string
- prog_name dd ? ; DWORD pointer to ASCIIZ
- ; program name.
- ;---------------------------------------------------------(8 bytes)
- arguments ends
-
- dos4BH proc near
- jmp short exec_code
- ;---------------------------- LOAD CONTROL BLOCK -----------------
- lcb_envir dw 0 ; Segment address of environment
- lcp_ps_o dw ? ; Offset of parameter string.
- lcb_ps_s dw ? ; Segment of parameter string.
- lcb_fcb1 dd 0 ; Dword pointer to FCB1
- ; (5CH in PSP).
- lcb_fcb2 dd 0 ; Dword pointer to FCB2
- ; (6CH in PSP).
- ;----------------------------- LOCAL VARIABLES -------------------
- ss_save dw ? ; Saved stack segment.
- sp_save dw ? ; Saved stack pointer.
- ;-----------------------------------------------------------------
- exec_code: push bp
- mov bp,sp ; Establish access to arguments.
- push ds ; Save the Turbo data segment.
- call relo1 ; Set BX to relocation
- ; factor: true offset ...
- relo1: pop bx ; of reloc1 minus local offset.
- sub bx,offset relo1
-
- les di,[bp].param_str ; Get offset:segment
- ; of parameter string.
- mov ax,es
- mov cs:lcb_ps_s[bx],ax ; Save parameter
- ; string segment ...
- mov cs:lcp_ps_o[bx],di ; ... and offset in LCB.
- mov ax,ss ; Save SS and SP registers
- mov cs:ss_save[bx],ax
- mov ax,sp
- mov cs:sp_save[bx],ax
-
- push cs ; Set up ES:BX as pointer
- ; to the LCB ...
- pop es
- add bx,offset lcb_envir
- lds dx,[bp].prog_name ; and DS:DX as pointer
- ; to the ASCIIZ ...
- inc dx ; ... program name.
- mov ax,4B00h ; DOS EXEC function: al=0, ah=4Bh
- int 21h ; Let her rip.
-
- sti ; Disable interrupts while stack messed up
- jc run_error ; Successful execution?
- xor al,al ; Yes, set error code=0.
- run_error: xor ah,ah
- call relo2 ; Recalculate relocation factor ...
- relo2: pop bx
- sub bx,offset relo2
- mov dx,cs:ss_save[bx] ; ... and restore the stack.
- mov ss,dx
- mov dx,cs:sp_save[bx]
- mov sp,dx
- cli ; Interrupts back on ... all done!
-
- pop ds
- pop bp
- ret 10 ; Pop arguments & "function result"
- dos4BH endp
- code ends
- end
-